package ioperations;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 姚东名
 * Date: 2024-06-01
 * Time: 23:59
 */
public class ReturnOperation implements Ioperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入您要归还的书名：");
        String name = scanner.nextLine();

        int currentSize = bookList.getUsedSize();

        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBooks(i);
            if(book.getName().equals(name)) {
                if(book.isBorrowed()) {
                    //证明这书是借出去的，把书借出的状态改变就行了
                    book.setBorrowed(false);
                    System.out.println("归还成功！");
                    return;
                }
            }
        }
        System.out.println("没有您要归还的书本！");
    }
}
